<template>
  <el-container class="home-container">
    <!-- 导航栏 -->
    <el-header>
      <!-- 导航栏左侧 -->
      <div class="left-header">
        <img src="../images/heima.png" alt />
        <span>电商管理后台</span>
      </div>
      <!-- 导航栏右侧 -->
      <el-button type="info" @click="logout">退出</el-button>
    </el-header>
    <el-container>
      <!-- 侧边栏 -->
      <el-aside width="200px" fixed>
        <el-menu background-color="#313743" text-color="#fff" unique-opened router active-text-color="#419AF9" :default-active="$route.path">
          <!-- 一级菜单 -->
          <el-submenu :index="item.id+''" v-for="item in menulist" :key="item.id">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>{{item.authName}}</span>
            </template>
            <!-- 二级菜单 -->
            <el-menu-item :index="'/' + subitem.path" v-for="subitem in item.children" :key="subitem.id"> 
              <i class="el-icon-menu"></i>
              <span>{{subitem.authName}}</span>
              </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <!-- 主体 -->
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>
<script>
export default {
  data() {
    return {
      //左侧菜单数据
      menulist: []
    };
  },
  created() {
    //获取菜单
    this.getMenus();
  },
  methods: {
    //   退出功能
    logout() {
      window.sessionStorage.clear();
      this.$router.push("/login");
    },
    // 获取左侧菜单方法
    async getMenus() {
      const { data: res } = await this.$http.get("menus");
      if (res.meta.status !== 200) return this.$message.error(res.meta.msg);
      this.menulist = res.data;
     // console.log(res);
    }
  }
};
</script>
<style lang="less" scoped>
.home-container {
  height: 100%;
}
.el-header {
  //position: fixed;
  background-color: #363d40;
  display: flex;
  justify-content: space-between;
  padding-left: 0;
  align-items: center;
  > div {
    display: flex;
    align-items: center;
    color: aliceblue;
    justify-content: space-between;
    span {
      margin-left: 15px;
    }
  }
}

.el-aside {
  //position:fixed;
  background-color: #313743;
  .el-menu{
    border-right: 0px;
  }
}
.el-main {
  background-color: #e9edf1;
}
</style>